<template>
  <view class="navbar" :style="{ paddingTop: safeAreaInsets!.top + 10 + 'px' }">
    <view class="logo">
      <image class="logo-image" src="@/static/images/logo.png" />
      <text class="logo-text">新鲜 · 亲民 · 快捷</text>
    </view>
    <navigator
      class="search"
      url="/pages/search/search"
      open-type="navigate"
      hover-class="navigator-hover"
    >
      <text class="icon-search">搜索商品</text>
      <text class="icon-scan" @tap.stop="scan"></text>
    </navigator>
  </view>
</template>

<script setup lang="ts">
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()

const scan = () => {
  // #ifdef MP-WEIXIN
  uni.scanCode({
    scanType: ['qrCode'],
    success: (success) => {
      console.log(success)
      uni.showToast({
        title: '扫码结果：' + success.result,
        duration: 2000,
      })
    },
  })
  // #endif
}
</script>

<style scoped lang="scss">
.navbar {
  background-image: url(@/static/images/navigator_bg.png);
  background-size: cover;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-top: 20px;

  .logo {
    display: flex;
    justify-self: center;
    align-items: center;
    height: 64rpx;
    padding-left: 30rpx;

    .logo-image {
      width: 166rpx;
      height: 39rpx;
    }
    .logo-text {
      flex: 1;
      line-height: 28rpx;
      color: #fff;
      /* 上边 | 右边 | 下边 | 左边 */
      margin: 2rpx 0 0 20rpx;
      padding-left: 20rpx;
      border-left: 1rpx solid #fff;
      font-size: 26rpx;
    }
  }
  .search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10rpx 0 26rpx;
    height: 64rpx;
    /* 上边下边 | 左边右边 */
    margin: 16rpx 20rpx;
    color: #fff;
    font-size: 28rpx;
    border-radius: 32rpx;
    background-color: rgb(255, 255, 255, 0.5);

    .icon-search {
      &::before {
        margin-right: 10rpx;
      }
    }

    .icon-scan {
      font-size: 30rpx;
      padding: 15rpx;
    }
  }
}
</style>
